﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;

    public class RFOutboundDA : IRFOutboundDA
    {
        private string SQL_SELECT_PICK_DETAIL_BY_VANNING_DETAIL = " SELECT PD.PICK_DETAIL_ID,PD.ORDER_ID,PD.ORDER_LINE_ID,PD.LOT,PD.OWNER_ID,PD.SKU_ID,PD.STATUS, PD.QTY,PD.LPN_ID,PD.UOM_ID,PD.PACK_ID,LA.EXTERNAL_LOT,LA.PRODUCE_DATE,LA.EXPIRY_DATE, LA.LOT_ATTR01,LA.LOT_ATTR02,LA.LOT_ATTR03,LA.LOT_ATTR04,LA.LOT_ATTR05,LA.LOT_ATTR06, LA.LOT_ATTR07,LA.LOT_ATTR08,LA.LOT_ATTR09,LA.LOT_ATTR10,SKU.DESCR AS SKU_DESCR, (SELECT ISNULL(SUM(VAND.QTY),0) FROM @_@VANNING_DETAIL VAND WHERE PICK_DETAIL_ID = PD.PICK_DETAIL_ID) AS LOAD_QTY  FROM @_@PICK_DETAIL PD  LEFT JOIN @_@LOT_ATTRIBUTE LA ON LA.LOT = PD.LOT  LEFT JOIN @_@SKU SKU ON SKU.OWNER_ID = PD.OWNER_ID AND SKU.SKU_ID = PD.SKU_ID";

        public List<RFPickDetailInfo> GetRFPickDetailListInfoByWhere(string where, string whLoginID)
        {
            string sql = this.SQL_SELECT_PICK_DETAIL_BY_VANNING_DETAIL + where;
            List<RFPickDetailInfo> rfPickDetailInfos = new List<RFPickDetailInfo>();
            RFPickDetailInfo rfPickDetailInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql.Replace("@_@", whLoginID)))
            {
                while (reader.Read())
                {
                    DateTime CS00001;
                    rfPickDetailInfo = new RFPickDetailInfo(reader["PICK_DETAIL_ID"].ToString(), reader["ORDER_ID"].ToString(), (reader["ORDER_LINE_ID"].ToString() != "") ? int.Parse(reader["ORDER_LINE_ID"].ToString()) : 0, reader["LOT"].ToString(), reader["OWNER_ID"].ToString(), reader["SKU_ID"].ToString(), reader["SKU_DESCR"].ToString(), reader["STATUS"].ToString(), (reader["QTY"].ToString() != "") ? decimal.Parse(reader["QTY"].ToString()) : 0M, reader["LPN_ID"].ToString(), reader["UOM_ID"].ToString(), reader["PACK_ID"].ToString(), reader["LOT_ATTR01"].ToString(), reader["LOT_ATTR02"].ToString(), reader["LOT_ATTR03"].ToString(), reader["LOT_ATTR04"].ToString(), reader["LOT_ATTR05"].ToString(), reader["LOT_ATTR06"].ToString(), reader["LOT_ATTR07"].ToString(), reader["LOT_ATTR08"].ToString(), reader["LOT_ATTR09"].ToString(), reader["LOT_ATTR10"].ToString(), (reader["PRODUCE_DATE"].ToString() != "") ? DateTime.Parse(reader["PRODUCE_DATE"].ToString()) : (CS00001 = new DateTime()), (reader["EXPIRY_DATE"].ToString() != "") ? DateTime.Parse(reader["EXPIRY_DATE"].ToString()) : (CS00001 = new DateTime()), reader["EXTERNAL_LOT"].ToString(), (reader["LOAD_QTY"].ToString() != "") ? decimal.Parse(reader["LOAD_QTY"].ToString()) : 0M);
                    rfPickDetailInfos.Add(rfPickDetailInfo);
                }
            }
            return rfPickDetailInfos;
        }
    }
}

